#!/bin/bash

# set the name of v8 shell
shell="./shell_g"

# a file arg is required
if [[ -z $1 ]] ; then
    echo "Usage: pretty.sh [-g] JSFILE"
    echo "       -g : use debug shell"
    exit
fi
file=$1

if [[ ! -f $shell ]] ; then
    # try parent dir
    shell=".$shell"
    if [[ ! -f $shell ]] ; then
        echo "Error: v8 $shell not found"
        exit
    fi
fi

# test javascript file exists
if [[ ! -f $file ]] ; then
    echo "Error: file $file not found"
    exit
fi


example="var source=read(\"$file\");print(JSON.AST.evaluate(source));"
#echo $example
$shell -e "$example"























